<template>
  <div class="pay-index">
    <van-nav-bar
      :title="orderObj.radio == 1 ? '微信支付' : '支付宝支付'"
      @click-left="$router.push('/')"
    >
      <van-icon slot="left" name="wap-home-o" />
    </van-nav-bar>
    <div class="tac"><img :src="orderObj.result.qrcode" alt="" /></div>
    <div class="price">￥{{ allFee }}</div>
    <div class="pay">
      <div class="collectPay flex jc-sb aic">
        <div>收款方</div>
        <div>{{ orderObj.result.company }}</div>
      </div>
      <div class="collectPay flex jc-sb aic">
        <div>剩余支付事件</div>
        <RestTime :time="time" />
      </div>
    </div>
  </div>
</template>

<script>
import RestTime from "@/components/RestTimr.vue";
import { get, post } from "@/request/index2";
export default {
  data() {
    return {
      orderObj: {},
      // 计时
      timer: "",
    };
  },
  created() {
    this.orderObj = JSON.parse(this.$route.query.orderObj);
    console.log("222", this.orderObj);
    this.yanzheng();
  },
  // beforeRouteLeave(to, from, next) {
  //   // ...
  //   if (this.timer) {
  //     clearInterval(this.timer);
  //   }
  //   next();
  // },
  destroyed() {
    if (this.timer) {
      clearInterval(this.timer);
    }
  },
  computed: {
    allFee() {
      return (this.orderObj.result.allFee / 100).toFixed(2);
    },
    time() {
      let time =
        15 * 60 * 1000 - (Date.now() - this.orderObj.result.createTime);

      if (time <= 0) {
        this.$router.push("/order/orderList");
      }
      return time;
    },
  },
  components: {
    RestTime,
  },
  methods: {
    yanzheng() {
      this.timer = setInterval(() => {
        post("/order/detail", { orderId: this.orderObj.result.orderId })
          .then((res) => {
            console.log(res);
            if (res.result.orderStatus == "01") {
              this.$router.push("/order/orderList");
            }
          })
          .catch((err) => console.log(err));
      }, 5000);
    },
  },
};
</script>

<style scoped>
.pay-index {
  background-color: #fff;
  height: 100vh;
}

.van-icon-wap-home-o:before {
  color: #000;
  font-size: 20px;
}
.price {
  text-align: center;
  margin-top: 20px;
  color: #2d3e4f;
  font-size: 30px;
  font-weight: 700;
  height: 45px;
  line-height: 45px;
}
.pay {
  width: 100vw;
  border-top: 1px solid #eae8e8;
  margin-top: 10px;
  color: #2c3e50;
}
.collectPay {
  height: 45px;
  font-size: 15px;
  margin: 0 15px;
}
</style>